/**
 * @Description : 第六章练习
 **/
const fs = require("fs");
const C6 = async (req, res) => {
    if (req.path) {
        let data = {};
        let tmpPath = req.path.split("/");
        if (fs.existsSync("./views/" + tmpPath[1] + "/" + tmpPath[2] + ".ejs")) {
            //判断视图文件是否存在
            if (tmpPath[2] === "6-3") {
                data = {
                    No: "221#",
                    orderTime: "2018-12-28 12:10",
                    orderPrice: [
                        {
                            menu: "麻辣烫",
                            orderNo: "*1",
                            price: "30.00"
                        },
                        {
                            menu: "可乐",
                            orderNo: "*2",
                            price: "5.00"
                        },
                        {
                            menu: "合计",
                            orderNo: "",
                            price: "40.00"
                        }
                    ]
                };
            } else if (tmpPath[2] === "test-6") {
                data = {
                    programList: [
                        {
                            No: "1",
                            name: "开场歌舞《万紫千红中国年》",
                            people: "凤凰传奇"
                        },
                        {
                            No: "2",
                            name: "魔术",
                            people: "李宁"
                        },
                        {
                            No: "3",
                            name: "小品《真假老师》",
                            people: "贾玲，白凯南"
                        }
                    ]
                };
            }
            res.render(tmpPath[1] + "/" + tmpPath[2], data);
        } else {
            res.render("error", { msg: tmpPath[1] + "/" + tmpPath[2] + ".ejs" + " 视图文件不存在" });
        }
    } else {
        res.render("error", { msg: "访问路径错误" });
    }
};

module.exports = { C6 };
